<?php
/**
 * @author Arsene Tochemey GANDOTE<arsene.gandote@yahoo.com>
 * @access public
 * @version 1.0
 * @copyright (c) 2011 - Tochemey. .
 */

# Instance of Module Model
$moduleObj =  ClassRegistry::init('Module');
# List of all the modules in the system
$allModules = $moduleObj->find('all', array('conditions'=>array('Module.active'=>1),'recursive' => -1, 'order' => 'Module.name ASC')); 

$loggedUser =  $this->Session->read('userSessionData');
$loggedUser_id = $loggedUser['id'];
$modified_date = date('Y-m-d H:i:s');
$created_date = date('Y-m-d H:i:s');
?>

 <?php echo $this->Form->create('User', array('default' => false, 'id' => 'user-form', 'action' => 'add','inputDefaults' => array('label' => false,'div' => false)));?>
  <div class="row-2">
      <table cellpadding="4" cellspacing="4" border="0">
         <tr>
                <td align="left" valign="middle" nowrap>User Name</td>
                <td align="left" valign="middle" nowrap>Password</td>
         </tr>
         <tr>
                <td><?php echo $this->Form->input('username', array('div' => false, 'label' => false, 'class' => 'validate[required,custom[noSpecialCaracters]] username')); ?></td>
                <td><?php echo $this->Form->input('password', array('div' => false, 'label' => false, 'class' => 'validate[required] password')); ?>  <?php echo $this->Form->input("created_by", array('type'=>'hidden','label' => false, 'value'=>"$loggedUser_id")); ?>  <?php echo $this->Form->input("creation_date", array('type'=>'hidden','label' => false, 'value'=>"$created_date")); ?></td>
         </tr>
          <tr>
                <td align="left" valign="middle" nowrap>First Name</td>
                <td align="left" valign="middle" nowrap>Last Name</td>
         </tr>
         <tr>
                <td><?php echo $this->Form->input('first_name', array('div' => false, 'label' => false, 'class' => 'validate[required,custom[noSpecialCaracters]] first_name')); ?></td>
                <td><?php echo $this->Form->input('last_name', array('div' => false, 'label' => false, 'class' => 'validate[required,custom[noSpecialCaracters]] last_name')); ?>  </td>
         </tr>
         <tr>
                <td colspan="2" align="center" valign="middle">Select the modules and their permissions that this user can use</td>
         </tr>
         <?php
            if(!empty($allModules)){
                $module_count = 0;
                foreach($allModules as $module){
                 ?>
                    <tr><td><?php echo $this->Form->input("ModulesUser.$module_count.module_id", array('type'=>'checkbox', 'div' => false, 'label' => false, 'class' => '', 'value'=>''.$module['Module']['id'].'')); ?><?php echo $module['Module']['name']; ?></td><td> <?php echo $this->Form->input("ModulesUser.$module_count.priv", array('options' => array('1'=>'READ', '2'=>'READ / WRITE', '3'=>'READ / WRITE / EXECUTE')));?>   <?php echo $this->Form->input("ModulesUser.$module_count.created_by", array('type'=>'hidden','label' => false, 'value'=>"$loggedUser_id")); ?>  <?php echo $this->Form->input("ModulesUser.$module_count.creation_date", array('type'=>'hidden','label' => false, 'value'=>"$created_date")); ?></td></tr>
                 <?php
                 $module_count++;
                }
            }
         ?>
	  </table>
    </div>
<?php echo $this->Form->end();?>
